package com.cn.wanxi.service.impl;

import com.cn.wanxi.entity.Result;
import com.cn.wanxi.entity.UserEntity;
import com.cn.wanxi.mapper.UserMapper;
import com.cn.wanxi.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService implements IUserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public Result login(UserEntity userEntity) {
        if (!userEntity.getCode().equals(userEntity.getSessionCode())) {
            return new Result("error-code", 0);
        }
        UserEntity entity = userMapper.findByUsernameAndPassword(userEntity);
        return new Result(entity == null ? "error" : "success", 0);

    }

    @Override
    public List<UserEntity> findAll(UserEntity userEntity) {

        return userMapper.findAll(userEntity);
    }

    @Override
    public Result getCount(UserEntity userEntity) {

        return new Result("", userMapper.getCount(userEntity));
    }
}
